{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alessandro Parisi \n",
      "last updated: 2019-04-17 \n",
      "\n",
      "CPython 3.5.4\n",
      "IPython 6.1.0\n",
      "\n",
      "numpy 1.15.2\n",
      "pandas 0.23.4\n",
      "matplotlib 2.2.2\n",
      "sklearn 0.20.0\n",
      "seaborn 0.8.0\n"
     ]
    }
   ],
   "source": [
    "%load_ext watermark\n",
    "%watermark -a \"Alessandro Parisi\" -u -d -v -p numpy,pandas,matplotlib,sklearn,seaborn\n",
    "# to install watermark launch 'pip install watermark' at command line\n",
    "import warnings \n",
    "warnings.simplefilter('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "               precision    recall  f1-score   support\n",
      "\n",
      " Colin Powell       0.92      0.89      0.90        79\n",
      "George W Bush       0.94      0.96      0.95       151\n",
      "\n",
      "    micro avg       0.93      0.93      0.93       230\n",
      "    macro avg       0.93      0.92      0.93       230\n",
      " weighted avg       0.93      0.93      0.93       230\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from sklearn.datasets import fetch_lfw_people\n",
    "from sklearn.decomposition import PCA\n",
    "from sklearn.neural_network import MLPClassifier\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import classification_report\n",
    "\n",
    "\n",
    "lfw = fetch_lfw_people(min_faces_per_person=150)\n",
    "\n",
    "X_data = lfw.data\n",
    "y_target = lfw.target\n",
    "names = lfw.target_names\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X_data, y_target, test_size=0.3)\n",
    "\n",
    "\n",
    "pca = PCA(n_components=150, whiten=True)\n",
    "pca.fit(X_train)\n",
    "\n",
    "pca_train = pca.transform(X_train)\n",
    "pca_test = pca.transform(X_test)\n",
    "\n",
    "\n",
    "mlpc = MLPClassifier()\n",
    "mlpc.fit(pca_train, y_train)\n",
    "\n",
    "y_pred = mlpc.predict(pca_test)\n",
    "print(classification_report(y_test, y_pred, target_names=names))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Py35",
   "language": "python",
   "name": "py35"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
